package com.youchuang.action.main;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Product;
import com.youchuang.common.Constant;
import com.youchuang.service.MainService;

import net.sf.json.JSONArray;

/**
 * 主页栏
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/main")
@ParentPackage("shopping-default")
public class FenceMainAction extends BaseAction {
	private Logger logger = Logger.getLogger(FenceMainAction.class.getSimpleName());
	private List<Product> products;

	@Resource
	private MainService mainService;

	@Action(value = "hotMain", results = { @Result(name = Constant.HOT, location = "/WEB-INF/jsp/main/hotFance.jsp") })
	public String hotMain() {
		logger.info("hotMain is execute");
		products = mainService.findProductByHot();
		logger.info("response json products = " + JSONArray.fromObject(products).toString());
		return Constant.HOT;
	}

	@Action(value = "newHotMain", results = {
			@Result(name = Constant.NEWHOT, location = "/WEB-INF/jsp/main/newHotFance.jsp") })
	public String newHotMain() {
		logger.info("newHotMain is execute");
		long time = 1000L * 60 * 60 * 24 * 120;
		products = mainService.findProductByNewHot(time);
		logger.info("response json products = " + JSONArray.fromObject(products).toString());
		return Constant.NEWHOT;
	}

	@Action(value = "newMain", results = { @Result(name = Constant.NEW, location = "/WEB-INF/jsp/main/newFance.jsp") })
	public String newMain() {
		logger.info("newMain is execute");
		products = mainService.findProductByNew();
		logger.info("response json products = " + JSONArray.fromObject(products).toString());
		return Constant.NEW;
	}

	@Action(value = "recommendMain", results = {
			@Result(name = Constant.RECOMMEND, location = "/WEB-INF/jsp/main/recommendFance.jsp") })
	public String recommendMain() {
		logger.info("recommendMain is execute");
		products = mainService.findProductLimmitByRandom();
		logger.info("response json products =" + JSONArray.fromObject(products).toString());
		return Constant.RECOMMEND;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

}
